package com.vgulu.server.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Administrator on 2014/9/15 0015.
 */
public class SHACipher {
    private final static Logger logger = LoggerFactory.getLogger(SHACipher.class);

    public  static String encryptSHA256(String text,String salt){
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.reset();
            md.update(text.getBytes());
            md.update(salt.getBytes());
            return TransformInHexAndString.stringToHexStr(md.digest());
        } catch (NoSuchAlgorithmException e) {
            logger.error("SHA256 init failure",e);
        }
        return null;
    }


    public static void main(String[]args){
        System.out.println(SHACipher.encryptSHA256("123456", "OT3Cxd5z"));
        System.out.println(SHACipher.encryptSHA256("123456", "OT3Cxd5z").equals("b0ea002ce8c4cdddecbe042106de7164e131a332d5521cff3997ffc85ba0d803"));
        System.out.println(SHACipher.encryptSHA256("qwerty", "GgnVLMEG").equals("5de37b7dc691eb3f910cd0640b2f5032b7e4c6e223fcc827437e06769f108282"));
    }
}
